package Day08_08;

public class Army {
    private Weapon[] w ;

    public Army() {
    }

    public Army(int i) {
        this.w = new Weapon[i];
    }
    public void addWeapon(Weapon wa) throws MyArrayOverreach{
        for (int i = 0; i < this.w.length; i++) {
                if(null == w[i]){
                    w[i] = wa;
                    return ;
                }
        }
            throw new MyArrayOverreach("数组下标越界了！！！");
    }

    public void attackAll(){
        for (int i = 0; i < this.w.length; i++) {
            if(w[i] instanceof Attackable){
                ((Attackable) w[i]).attack();
            }
        }
    }

    public void moveAll(){
        for (int i = 0; i < this.w.length; i++) {
            if(w[i] instanceof Moveable){
                ((Moveable) w[i]).move();
            }
        }

    }
}
